package com.sdp.th.task;

import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sdp.core.bizc.vo.Result;
import com.sdp.right.cron.ScheduledOfTask;
import com.sdp.right.websocket.dto.MessageInfo;
import com.sdp.right.websocket.server.MessageWebsocketServer;
import com.sdp.th.controller.ThReportController;
import com.sdp.th.utils.ThConstants;

@Component
public class EqAndAlarmCountTask implements ScheduledOfTask{
	
	@Autowired
	private MessageWebsocketServer messageWebsocketServer;
	
	@Autowired
	private ThReportController thReportController;

	@Override
	public void execute() {
		
		Map<String, Map<String, String>> empClientIdMap = MessageWebsocketServer.getEmpClientIdMap();
		if(empClientIdMap==null || empClientIdMap.size()==0) {
			return;
		}
		
		Result<?> r = thReportController.queryEqAndAlarmCount();
		
		if(!r.isSuccess()) {
			return;
		}
		
		for (Entry<String, Map<String, String>> entry : empClientIdMap.entrySet()) {
			MessageInfo messageInfo = new MessageInfo();
			messageInfo.setData(r.getResult());
			messageInfo.setEmpNo(entry.getKey());
			messageInfo.setType(ThConstants.websocket_设备和已报警数量.getCode());
			messageWebsocketServer.sendMessage(messageInfo);
		}
		
		
		
	}

}
